package com.example2;

import java.util.Scanner;

/**
 * @author Yancy
 * @program springioctest
 * 判断是否为质数
 * @create 2020-08-28
 */
public class PrimeNumber {

  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);
    System.out.println("请输入一个数：");
    int a = scanner.nextInt();
    prime(a);

    //    if (a % 1 == 0 && a % a == 0) {
    //      System.out.println(a + "是质数！");
    //    }
    //    System.out.println(a + "不是质数！");
  }

  public static boolean prime(int a) {
    int b = 2;
    int c = 3;
    if (a < b) {
      System.out.println(a + "不是质数！");
      return false;
    }
    if (a == b || a == c) {
      System.out.println(a + "是质数！");
    } else {
      int n = (int) Math.sqrt(a);
      for (int i = 2; i <= n; i++) {
        if (a % i == 0) {
          System.out.println(a + "不是质数！");
          return false;
        }
      }
      System.out.println(a + "是质数！");
    }

    return true;
  }
}
